package com.test.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport 的 park 和unpark
 */
public class LockSupportDemo {
    public static void main(String[] args) {
        Thread a = new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"\t"+"----come in");
            LockSupport.park();//被阻塞，等待通知/放行
           // LockSupport.park();
            System.out.println(Thread.currentThread().getName()+"\t"+"-------唤醒");
        },"A");
        a.start();

        try {
            TimeUnit.SECONDS.sleep(3l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        new Thread(()->{
            LockSupport.unpark(a);
           // LockSupport.unpark(a);
            System.out.println(Thread.currentThread().getName()+"\t"+"-------通知");

        },"B").start();
    }
}
